//
//  HttpRequest.m
//
//  Created by Mikey on 15/6/8.
//  Copyright (c) 2015年 hhxh. All rights reserved.
//

#import "HttpRequest.h"
#import "AFNetworking.h"

//#define Request(path) [[AFHTTPRequestOperationManager manager] POST:(Service_IP path) parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {\
//success(responseObject);\
//} failure:^(AFHTTPRequestOperation *operation, NSError *error) {\
//    failure(error);\
//}]
/**
 *本类描述:网络请求层封装
 */
@implementation HttpRequest
#pragma mark---------------单例---------------
+(HttpRequest *)shareManager{
    static HttpRequest *request;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        request = [[HttpRequest alloc]init];
    });
    return  request;
}
#pragma mark---------------GET请求---------------
+(void)getWithPath:(NSString *)path params:(NSDictionary *)params success:(SuccessBlock)success failure:(FailureBlock)failure{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    [manager GET:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        success(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure(error);
    }];
}
#pragma mark---------------POST请求---------------
+(void)postWithPath:(NSString *)path params:(NSDictionary *)params success:(SuccessBlock)success failure:(FailureBlock)failure{
    [[AFHTTPRequestOperationManager manager] POST:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        success(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure(error);
    }];
}
#pragma mark*********************************所有的数据请求都在这里*****************************

@end